<?php


namespace App\Libs;


/**
 * 响应格式类
 *
 * Class ResponseFormat
 *
 * @package App\Libs
 */
class ResponseFormat
{
    private function __construct() {}

    private function __clone() {}


    /**
     * API
     *
     * @param bool $success
     * @param int $errCode
     * @param string $desc
     * @param array $resultData
     *
     * @return array
     */
    public static function apiFormat($success = true, $errCode = 0, $desc = 'success', $resultData = [])
    {
        return [
            'success'   =>  $success,
            'errCode'   =>  $errCode,
            'desc'      =>  $desc,
            'resultData'=>  $resultData
        ];
    }

    /**
     * AJAX
     *
     * @param int $state
     * @param string $msg
     * @param array $data
     * @param int $count
     * @param array $attach
     *
     * @return array
     */
    public static function ajaxFormat($state = 1, $msg = '操作成功', $data = [], $count = 0, $attach = [])
    {
        return [
            'state' =>  $state,
            'msg'   =>  $msg,
            'data'  =>  $data,
            'count' =>  $count,
            'attach'=>  $attach
        ];
    }
}
